# slide_rest.py

from __future__ import division

from ot_simulator.component import component

class slide_rest(component.component):
    '''This simulates the slide rest.

    The chuck spindle describes a circle twice as the chuck turns through one
    revolution.  The circle has a diameter of ``e`` centered at ``(e/2, 0)``.

    ===============  ========================================================
     Input setting   
    ===============  ========================================================
    mount_offset     The position (in Z) where the slide rest is mounted to
                     the bed of the lathe.  default 0.
    angle            The angle of the SR to the lathe.  0 degrees puts the
                     slide rest parallel to the bed of the lathe.  Positive
                     angles rotate counter-clockwise.  90 puts it
                     perpendicular to the bed of the lathe.  default 0.
    sr               handwheel setting.  0 places the toolbox directly over
                     the pivot of the slide_rest.  Positive numbers move the
                     toolbox to the right (+Z if the angle is zero, +X if the
                     angle is 90).  default 0.
    tool_angle       angle of tool in relation to SR.  Zero is perpendicular
                     to the slide_rest longitudinal axis.  Positive is
                     counter-clockwise.  default 0.
    tool_offset      applied as final offset along tool Z axis.  0 is lathe
                     center of rotation.  Positive moves tool away from the
                     work.  This can be driven by a template.  default 0.
    ===============  ========================================================

    ===============  ==========================
    Output setting
    ===============  ==========================
    <none>
    ===============  ==========================
    '''
    input_parameters = ('mount_offset', 'angle', 'sr', 'tool_angle',
                        'tool_offset')

    def get_transform(self, params, transform_in):
        transform_out = \
          transform_in.move(z = self.get_param(params, 'mount_offset', 0))
        transform_out = \
          transform_out.rotate_y(self.get_param(params, 'angle', 0))
        transform_out = \
          transform_out.move(z = self.get_param(params, 'sr', 0))
        transform_out = \
          transform_out.rotate_y(
            self.get_param(params, 'tool_angle', 0.0) - 90.0)
        transform_out = \
          transform_out.move(z = self.get_param(params, 'tool_offset', 0))
        return transform_out


def test():
    import doctest
    import sys
    sys.exit(doctest.testmod()[0])

if __name__ == "__main__":
    test()
